package org.ofbiz.sys.utils;

import javax.servlet.http.HttpServletRequest;

public class ApiResponse {

    public ApiResponse(HttpServletRequest request, String result, String message, String code, Object... msgParam) {
	super();
	this.result = result;
	this.code = code;
	if (code.equals("0")||code.equals("\"0\"")) {
	    this.success = true;
	} else {
	    this.success = false;
	}
	try {
	    this.message = "\"" + message + "\"";
	} catch (Exception e) {
	    this.message = "\"" + message + "\"";
	}
    }

    /**
     * 返回信息主体
     */
    public String getResult() {
	return result;
    }

    public void setResult(String result) {
	this.result = result;
    }

    /**
     * API调用提示信息
     */
    public String getMessage() {
	return message;
    }

    public void setMessage(String message) {
	this.message = message;
    }

    /**
     * API接口调用状态
     */
    public String getStatus() {
	return status;
    }

    public void setStatus(String status) {
	this.status = status;
    }

    public boolean getSuccess() {
	return success;
    }

    public void setSuccess(boolean success) {
	this.success = success;
    }

    public String getCode() {
	return code;
    }

    public void setCode(String code) {
	this.code = code;
    }

    @Override
    public String toString() {
	return "{\"result\":" + result + ",\"success\":" + success + ", \"message\":" + message + ", \"code\":" + code + "}";
    }

    public String sourceToString() {
	return "{\"source\":" + result + ", \"message\":" + message + ", \"code\":" + code + "}";
    }

    private String result;
    private String message;
    private String status;
    private String code;
    private boolean success;
}
